#pragma once

#include "G.h"
#include "client/iclient.h"
#include "client/iwindow.h"
#include "debug/logger.h"

#include "messiah/resource/repo/repository.h"
#include "messiah/resource/world/iworld_manager.h"
#include "messiah/resource/repo/repo_item.h"
#include "messiah/resource/find_similar_texture.h"
#include "image/image_loader.h"

namespace renderit
{
	class repo_tools
	{
	public:
		repo_tools();

	public:
		void start_game();

	private:
		void do_console_input(const std::string& input);

		void do_console_ls_repos(const std::vector<std::string>& params);
		void do_console_ls_worlds(const std::vector<std::string>& params);

		void do_console_load(const std::vector<std::string>& params);
		void loaded_complete();
		void do_console_load_tmp_repos(const std::vector<std::string>& params);
		void loaded_tmp_repos();

		void do_console_print_repos(const std::vector<std::string>& params);
		void do_console_print_repo(const std::vector<std::string>& params) {}
		void do_console_print_worlds(const std::vector<std::string>& params) {}
		void do_console_print_world(const std::vector<std::string>& params) {}

		void do_console_ls_uncollect(const std::vector<std::string>& params);
		void do_console_remove_uncollect(const std::vector<std::string>& params);

		void do_console_ls_duplicated(const std::vector<std::string>& params);
		void gen_md5_complete();
		void do_console_remove_duplicated(const std::vector<std::string>& params);

		void do_console_ls_remote_refs(const std::vector<std::string>& params);
		void do_console_move_refs_from(const std::vector<std::string>& params);

	private:
		// repo & worldm
		messiah::repository * repo_;
		messiah::iworld_manager * wm_;
		uint8 loading_state_;

		messiah::repository * repo_tmp_;

		// duplicated files
		std::map<std::string, std::vector<messiah::repo_item*>> md5_to_items_;

		// remote refs (guids)
		std::vector<std::string> remote_refs_;

		// Console Commands
		typedef std::function<void(const std::vector<std::string>&)> console_p_t;
		std::vector<std::pair<std::string, console_p_t>> console_processors_;
	};
}